package org.nobject.common.fan.datagen;

import org.nobject.common.lang.ObjectUtils;

/**
 * 字符串生成器
 *
 * @author benson
 * @version 1.0
 */
public class StringGen implements RandomGen{
	
	public static int TYPE_09=0;
	
	public static int TYPE_AZ=1;
	
	public static int TYPE_09AZ=2;
	
	public static int TYPE_09az=4;
	
	public static int TYPE_ZHCN=3;
	
	public static char [] c09={'0','1','2','3','4','5','6','7','8','9'};
	public static char [] caz={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	public static char [] cAZ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	public static char [] c09AZ=new char[cAZ.length+c09.length];
	public static char [] c09az=new char[caz.length+c09.length];
	public static String [] cZHCN=new String[]{"珍","曼","柔","晨","友","蝶","雪","靖","小","丰","彤","莲","丝","仁","国","恨","柳","猛","元","长","傲","听","兰","盛","映","寒","文","代","泰","发","语","双","武","青","蕊","秋","迎","含","南","荷","奋","竹","依","寻","昌","孤","思","盼","如","花","雁","晴","夜","听","若","乐","紫","琪","飞","凌","灵","大","碧","怀","丹","诗","筠","云","海","初","玉","阳","腾","穿","忆","槐","江","宜","儿","露","巧","涵","幻","隆","惜","兴","昆","萍","祥","新","萱","冬","波","宛","半","亦","菡","书","绮","室","怜","柏","谷","醉","梅","天","问","尔","采","巧","和","晓","凰","烟","冰","尊","科","兰","寄","蓝","绿","香","白","卉","岚","容","平","薇","冷","妙","旋","翠","妙","春","念","幼","向","威","枫","琴","松","蕾","姿","千","风","瑶","成","觅","真","旋","访","美","之","雨","从","蓉","顺","水","福","珊","芙","奥","雅","凡","瑞","易","梦","静","凤","博","丹","菱","意","慕","山","安"};
	static{
		System.arraycopy(c09, 0, c09AZ, 0, c09.length);
		System.arraycopy(cAZ, 0, c09AZ, c09.length, cAZ.length);
		System.arraycopy(c09, 0, c09az, 0, c09.length);
		System.arraycopy(caz, 0, c09az, c09.length, cAZ.length);
	}
	
	/** 
	 * 生成字符串
	 * 
	 * EXP:
	 * genString(2+random.nextInt(3),3)
	 * 
	 * @param length
	 * @param type
	 * @return
	 */
	public static String genString(int length,int type){
		StringBuffer sb=new StringBuffer();
		if(ObjectUtils.in(type, new Integer[]{TYPE_09,TYPE_AZ,TYPE_09AZ,TYPE_09az})){
			char [] cs=c09AZ;
			if(type==TYPE_09){
				cs=c09;
			}else if(type==TYPE_AZ){
				cs=cAZ;
			}else if(type==TYPE_09AZ){
				cs=c09AZ;
			}else if(type==TYPE_09az){
				cs=c09az;
			}
			
			for (int i = 0; i < length; i++) {
				sb.append(cs[random.nextInt(cs.length)]);
			}
		}else if(type==TYPE_ZHCN){
			for (int i = 0; i < length; i++) {
				sb.append(cZHCN[random.nextInt(cZHCN.length)]);
			}
		}
		
		return sb.toString();
	}
	
}
